package 一致性组合模式;

import java.util.ArrayList;
import java.util.Iterator;

public class Organization extends Component {
    private String name;
    public String text=" ";
    private ArrayList<Component> member=new ArrayList<Component>();
    public Organization(String name)
    {
    	this.name=name;
    }
	@Override
	public String showRelationship() {
		int len=member.size();
		for(int i=0;i<len;i++)
		{
			Component c=member.get(i);
			text=text+c.showRelationship();
		}
		return  "组织"+name+text+" ";
	}
   @Override
	public void add(Component c)//组织中添加组织或者个人
	{
		if(c!=null)member.add(c);
	}
	@Override
	public void remove(String str)//组织中删除组织或个人
	{
		 for(Iterator<Component>it =member.iterator();it.hasNext(); )
		 {
			 Component c =it.next();
			 if(c instanceof Organization)
			 {
				 if(((Organization)c).name.equals(str))
					 it.remove();
			 }
			 else
			 {
				 if(((Person)c).name.equals(str))
					 it.remove();
			 }
		 }
	}

}
